import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo2 {
    public static void main(String[] args) throws SQLException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的id:");
        int id = scanner.nextInt();

        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java14?characterEncoding=utf8&useSSL=false");//向下转型
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("808250");

        Connection connection = dataSource.getConnection();

        String sql = "delete from student where id = 1";
        PreparedStatement statement = connection.prepareStatement(sql);
        int n = statement.executeUpdate();
        System.out.println("n = "+ n);

        statement.close();
        connection.close();;



    }
}
